<?if(!$GLOBALS['no_myjs']) { ?>
function $(id)
{
	return document.getElementById(id);
}
function $t(tagname)
{
	return document.getElementsByTagName(tagname);
}
<? } ?>
function check_rs(rs, noalert) {
	if(typeof(rs.status) !== 'undefined') {
		if(rs.status == 1) {
			return true;
		} else if(rs.status == -1) {
			LocalStorage.removeItem(config_prefix+'_admininc_token');

			location.href = "?act=login";
		} else if(rs.status == 9) {
			location.href = rs.data.url;
		} else {
			if(!noalert) alert(rs.message);
			return false;
		}
	} else {
		if(!noalert) alert("加载失败，请重试！");
		return false;
	}
	return false;
}
var alertCloseFunc = null;
function closeAlert() {
	$G.hide_div("fdiv_alert", true, 'cover_alert');
	if(alertCloseFunc) {
		alertCloseFunc();
		alertCloseFunc = null;
	}
}
function myAlert(str, height, func) {
	if(!height) height = 100;
	$("fdiv_alert").style.height = (height+100)+'px';
	$("alert_msg_div").style.height = (height+70)+'px';
	$("alert_msg").style.height = height+'px';

	$("alert_msg").innerHTML = str;
	
	$("alert_bt_div").innerHTML = '<input id="galert_bt" type="button" class="button" value="关闭" onclick="closeAlert()" />';
	if($("galert_bt")) $("galert_bt").disabled = false;
	$G.show_div("fdiv_alert", <?=($isphone?280:400)?>, height+100, 'cover_alert', 19);
	

	if(func) alertCloseFunc = func;
	else alertCloseFunc = null;
}
<? if($isphone && !$GLOBALS['no_phone_alert']) { ?>
window.alert = function(name){
	try {
		var iframe = document.createElement("iframe");
		iframe.style.display="none";
		iframe.name = 'alertifr';
		if(typeof androidJs != 'undefined') iframe.setAttribute("src", 'javascript:alert(decodeURIComponent("'+encodeURIComponent(name)+'"));');
		else iframe.setAttribute("src", 'data:text/plain');
		document.documentElement.appendChild(iframe);
		if(typeof androidJs == 'undefined') window.frames['alertifr'].window.alert(name);
		iframe.parentNode.removeChild(iframe);
	} catch (e) {
		alert(name);
	}
	
}
<? } ?>

var UserData = { 
	userData : null,
	name : location.hostname,
	init:function(){
	if (!UserData.userData) {
	try {
	UserData.userData = document.createElement('INPUT');
	UserData.userData.type = "hidden";
	UserData.userData.style.display = "none";
	UserData.userData.addBehavior ("#default#userData");
	document.body.appendChild(UserData.userData);
	var expires = new Date();
	expires.setDate(expires.getDate()+365);
	UserData.userData.expires = expires.toUTCString();
	} catch(e) {
	return false;
	}
	}
	return true;
	},


	setItem : function(key, value) {//设置缓存
	if(UserData.init()){
	UserData.userData.load(UserData.name);
	UserData.userData.setAttribute(key, value);
	UserData.userData.save(UserData.name);
	}
	},


	getItem : function(key) {//获取缓存
	if(UserData.init()){
	UserData.userData.load(UserData.name);
	var v = UserData.userData.getAttribute(key);
	if(typeof(v) == 'undefined') v = null;
	return v;
	}
	},


	removeItem : function(key) {  //删除缓存
	if(UserData.init()){
	UserData.userData.load(UserData.name);
	UserData.userData.removeAttribute(key);
	UserData.userData.save(UserData.name);
	}
	},

	clear:function(){//清除所有缓存
   UserData.userData.load(UserData.name);
   var now = new Date();
   now = new Date(now.getTime()-1);
   UserData.userData.expires = now.toUTCString();
   UserData.userData.save(UserData.name);
   }
};


var LocalStorage = {//新建一个LocalStorage对象
	setItem:function(key,value) //设置缓存
	{
		if(typeof(localStorage) != 'undefined') {
		localStorage.setItem(key,value)
		}
		else{
		UserData.setItem(key,value)
		}
	},
	getItem:function(key)
	{
	if(typeof(localStorage) != 'undefined')
	{
		return localStorage.getItem(key)
	} else{
		return UserData.getItem(key);
	}


	},
	removeItem:function(key)
	{
	if(typeof(localStorage) != 'undefined')
	{
	return localStorage.removeItem(key)
	}
	else
	{
		return UserData.removeItem(key);
	}


	},
	clear:function()
	{
	if(typeof(localStorage) != 'undefined')
	{
	return localStorage.clear();
	}
	else{
	return UserData.clear()
	}

	}
};
var $G = {

	gIsIE: ( ((navigator.userAgent.toLowerCase().indexOf('msie') != -1) || (navigator.userAgent.toLowerCase().indexOf('trident') != -1)) ? true : false),
	gIsIE6: ((navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) ? true : false),
	
	rm: function(id)
	{
		if($(id)) 
			$(id).parentNode.removeChild($(id));
	},
	cover: function(height, id, zidx)
	{
		var color = '#666666';
		var alpha = 40;
		var magin = 0;
		
		var alpha2 = alpha / 100;
	
		if(!id) id = "cover_div_dasda";
		if(!zidx) zidx = 14;
		if($(id)) {
			this.rm(id);
		}
		var div = document.createElement('div'); 
		div.id = id;
		div.style.position = 'absolute';
		if(!height) height = document.documentElement.clientHeight;
		var width = document.documentElement.clientWidth;

		
		div.style.width = width + 'px';
		div.style.height = height + 'px';
		div.style.backgroundColor = color;
		div.style.left = '0px';
		div.style.top = '0px';
		div.style.zIndex = zidx+'';
		div.style.filter = 'alpha(opacity=' + alpha + ')';
		div.style.transition = 'opacity 0.3s ease';
		div.style.opacity = 0;
		document.body.appendChild(div);

		void div.offsetWidth;
		div.style.opacity = alpha2;
	},

	uncover: function(id)
	{
		if(!id) id = "cover_div_dasda";
		if(!$(id)) return ;
		$(id).style.transition = 'opacity 0.3s ease';
		$(id).style.opacity = '0';
		
		setTimeout(function() {
			$G.rm(id);
		}, 400);

	},
	show_div: function(id, width, height, cover_id, cover_zidx)
	{
		this.cover(null, cover_id, cover_zidx);
		var cwidth = document.documentElement.clientWidth;
		var ctop = document.documentElement.scrollTop;
		if(cwidth == 0) cwidth = document.body.clientWidth;
		if(ctop == 0) ctop = document.body.scrollTop;

		var cheight = document.documentElement.clientHeight;

		if(cheight == 0) cheight = document.body.clientHeight;

		var left = parseInt((cwidth-width)/2);
		var top = parseInt((cheight-height)/2) + ctop - 20;
		if(top < 0) top = 0;

		$(id).style.left = left + 'px';
		$(id).style.top = top + 'px';
		
		$(id).style.display = 'block';
		if(this.gIsIE) return ;
		$(id).style.opacity = '0';
		$(id).style.transition = 'opacity 0.3s ease';
		void $(id).offsetWidth;
		$(id).style.opacity = '1';

	},
	hide_div: function(id, p, cover_id)
	{
		if(p !== false) this.uncover(cover_id);
		if(this.gIsIE) {
			$(id).style.display = 'none';
			return ;
		}
		$(id).style.transition = 'opacity 0.3s ease';
		$(id).style.opacity = '0';
		setTimeout(function() {
			$(id).style.display = 'none';
		}, 400);
	},
	
	trim: function(str) 
	{ 
		if(str == null || typeof(str) == "undefined") return "";
		for(var i = 0 ; i<str.length && (str.charAt(i)==" " || str.charAt(i)=="　") ; i++) ; 
		for(var j =str.length; j>0 && (str.charAt(j-1)==" " || str.charAt(j-1)=="　") ; j--) ; 
		if(i>j) return ""; 
		return str.substring(i,j); 
	},
	str_replace: function(str, s, r) 
	{
		var regex = new RegExp(s, "g");
		return str.replace(regex, r);
	},
	set_len: function(str, len, r)
	{
		if(typeof(r) == 'undefined') r = '...';
		if(str.length > len) str = str.substr(0, len - 1) + r;
		return str;
	},
	get_key: function() {
		var key = '';
		for(var i = 1; i <= 32; i++) { 
			var r = Math.floor(Math.random()*70)+48;
			key += String.fromCharCode(r); 
		}
		return key;
	},
	ajax: function(url, data, func, type, method, nodec)
	{
		var xmlhttp = false;
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e2) {
				xmlhttp = false;
			}
		}
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
	
		var param = "rtime=" + new Date().getTime()+"&sw="+screen.width+"&sh="+screen.height;
		for(key in data) {
			param += "&" + key + "=" + encodeURIComponent(data[key]);
		}
		var token = LocalStorage.getItem(config_prefix+'_admininc_token');
		if(token != null && token != '') {
			param += "&token=" + encodeURIComponent(token);
		}
		<? if($config_rsa_pubkey) { ?>
			var key = $G.get_key();
			param = this.aes_encrypt(param, key);
			var enc_key = this.rsa_encrypt(key);
			param = "v="+encodeURIComponent(enc_key+"#"+param);
		<? } ?>

		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded;");
		xmlhttp.send(param);

		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4) {
				var rs_o = xmlhttp.responseText;
				<? if($config_rsa_pubkey) { ?>
					if(!nodec) rs_o = $G.aes_decrypt(rs_o, key);
				<? } ?>
				if(type == 'json') {
					var rs;
					try{
						rs = eval('(' + rs_o + ')');
					} catch (e){
						rs = rs_o;
					}
					func(rs);
				}
				else func(rs_o);
			}
		};
	},
	submitForm: function(fname) {
		var form;
		if(typeof(fname) == 'string') form = document.forms[fname];
		else form = fname;

		var token = LocalStorage.getItem(config_prefix+'_admininc_token');

		<? if($config_rsa_pubkey) { ?>
			
			var hasv = false;
			var param = "rtimeform=" + new Date().getTime();
			for(var i=0; i < form.length; i++){
				var e = form[i];
				if(e.name == 'v') {
					hasv = e;
					continue;
				}
				if(e.type != "file" && e.type != "button" && e.type != "submit" && e.name != 'picdata'){
					param += "&" + e.name + "=" + encodeURIComponent(e.value);
					if(e.name != 'upload_type') e.value = '';
				}
			}
			
			if(token != null && token != '') {
				param += "&token=" + encodeURIComponent(token);
			}
			var key = $G.get_key();
			param = $G.aes_encrypt(param, key);
			var enc_key = $G.rsa_encrypt(key);
			var v = enc_key+"#"+param;

			if(!hasv) {
				var newInput = document.createElement("input");  
				newInput.type = 'hidden';  
				newInput.name = "v"; 
				newInput.value = v; 
				form.appendChild(newInput); 
			} else {
				hasv.value = v;
			}
			
		<? } else { ?>
		if(token != null && token != '') {

			var hasv = false;
			for(var i=0; i < form.length; i++){
				var e = form[i];
				if(e.name == 'token') {
					hasv = e;
					break;
				}
			}


			if(!hasv) {
				var newInput = document.createElement("input");  
				newInput.type = 'hidden';  
				newInput.name = "token"; 
				newInput.value = token;
				form.appendChild(newInput); 
			} else {
				hasv.value = token;
			}
			
		}
	    <? } ?>
		form.submit();
	},
	
	getValue: function(id)
	{
		var obj = document.getElementsByName(id);
		if(obj.length == 0 || obj[0].getAttribute("id") == id) obj = document.getElementById(id);
		else obj = obj[0];
		var nodeName = 'text';
		try{
			nodeName = obj.nodeName.toLowerCase();
		} catch(e){
			try {return this.trim(obj.value);}catch (e) {return '';}
		}
		if(nodeName == "select" || nodeName == "textarea") return this.trim(obj.value);
		var type = obj.getAttribute("type");
		if(type == "radio") {
			obj = document.getElementsByName(id);
			for(var i = 0; i < obj.length; i++)
				if(obj[i].checked)
					return obj[i].value;
			return "";
		} else if(type == "checkbox") {
			obj = document.getElementsByName(id);
			var arr = [];
			for(var i = 0; i < obj.length; i++)
				if(obj[i].checked)
					arr.push(obj[i].value);
			if(arr.length == 0) return '';
			return arr.join(",");
		} else {
			return this.trim(obj.value);	
		}
	},
	setValue: function(id, value)
	{
		if(typeof(value) == "undefined") value = "";
		var obj = document.getElementsByName(id);
		if(obj.length == 0) obj = document.getElementById(id);
		else obj = obj[0];
		var nodeName = 'text';
		try{
			nodeName = obj.nodeName.toLowerCase();
		} catch(e){
			obj.value = this.trim(value);
			return ;
		}
		var nodeName = obj.nodeName.toLowerCase();
		if(nodeName == "select") {
			if(this.trim(value) != '') obj.value = this.trim(value); 
			else obj.options.selectedIndex = 0;
			return ; 
		}
		var type = obj.getAttribute("type");
		if(type == "radio") {
			obj = document.getElementsByName(id);
			for(var i = 0; i < obj.length; i++) {
				obj[i].checked = false;
				if(obj[i].value == value)
					obj[i].checked = true;
			}
		} else if(type == "checkbox") {
			obj = document.getElementsByName(id);
			for(var i = 0; i < obj.length; i++) {
				if(value === 1) { obj[i].checked = true; continue; }
				obj[i].checked = false;
				for(var j = 0; j < value.length; j++) {
					if(value[j] == obj[i].value)
						obj[i].checked = true;
				}
			}
		} else {
			obj.value = this.trim(value); 	
		}
	},
	show: function(id, type)
	{
		if(typeof(type) == "undefined") type = 'block';
		document.getElementById(id).style.display = type;
	},
	hide: function(id)
	{
		document.getElementById(id).style.display = "none";
	},
	disable: function(id)
	{
		document.getElementById(id).disabled = true;
	},
	enable: function(id)
	{
		document.getElementById(id).disabled = false;
	},
	
	setWidth: function(str, len)
	{
		if(len <= 0) return "";
		var p = 0;
		while(str_width(str) >= len) {
			p = 1;
			str = str.substr(0, str.length - 1);
		}
		if(p == 1) str += "..";
		return str;
	
	},
	
	json_encode: function(input)
	{ 
		if (typeof(input) == 'undefined' || input == null) return 'null' ;
		switch (input.constructor) { 
		  case String: return '"' + this.addslashes(input) + '"';
		  case Number: return input.toString();
		  case Boolean: return input.toString();
		  case Array : 
			var buf = [];
			for (i in input) 
			  buf.push(this.json_encode(input[i]));
				return '[' + buf.join(', ') + ']';
		  case Object: 
			var buf = [];
			for (k in input) 
			  buf.push('"' + k + '" : ' + this.json_encode(input[k]));
				return '{' + buf.join(', ') + '} ';
		  default: 
			return 'null';
		} 
	},
	
	check_date: function(date)
	{
		var reg = /^(\d){4}-(\d){2}-(\d){2}$/;
		if(!date.match(reg)) {
			return false;
		}
		var arr = date.split("-");
		
		if(arr[0].length != 4) return false;
		if(Number(arr[1]) > 12 || Number(arr[1]) <= 0) return false;
		if(Number(arr[2]) > 31 || Number(arr[2]) <= 0) return false;
		return true;
	},
	check_time: function(time)
	{
		var reg = /^(\d){4}-(\d){2}-(\d){2} (\d){2}:(\d){2}:(\d){2}$/;
		if(!time.match(reg)) {
			return false;
		}
		var arr1 = time.split(" ");
		var arr2 = arr1[0].split("-");
		var arr3 = arr1[1].split(":");
		if(Number(arr2[1]) > 12 || Number(arr2[1]) <= 0) return false;
		if(Number(arr2[2]) > 31 || Number(arr2[2]) <= 0) return false;
		if(Number(arr3[0]) >= 24 || Number(arr3[0]) < 0) return false;
		if(Number(arr3[1]) >= 60 || Number(arr3[1]) < 0) return false;
		if(Number(arr3[2]) >= 60 || Number(arr3[2]) < 0) return false;
		return true;
	},
	
	check_int: function(str, fu)
	{
		if(str == '0') return true;
		if(fu) var reg = /^(\-)?[1-9][0-9]*$/;
		else var reg = /^[1-9][0-9]*$/;
		if(!str.match(reg)) {
			return false;
		}
		return true;
	},
	
	check_number: function(str)
	{
		if(str == '0') return true;
		var reg = /^[0-9]+(\.\d+)?$/;
		if(str.match(reg)) {
			return true;
		}
		return false;
	},
	scroll: function(func)
	{
		if(this.gIsIE) window.attachEvent("onscroll", func);
		else window.addEventListener("scroll", func, false);
	},
	load: function(func)
	{
		if(this.gIsIE) window.attachEvent("onload", func);
		else window.addEventListener("load", func, false);
	},
	dateToStr: function(date, type)
	{
		if(!date) return "";
		var y = date.getFullYear()+"";
		var m = (date.getMonth()+1)+""; if(m.length == 1) m = "0" + m;
		var d = date.getDate()+""; if(d.length == 1) d = "0" + d;
		var h = date.getHours()+""; if(h.length == 1) h = "0" + h;
		var i = date.getMinutes()+""; if(i.length == 1) i = "0" + i;
		var s = date.getSeconds()+""; if(s.length == 1) s = "0" + s;
		if(!type) {
			return  y + "-" + m + "-" + d + " " + h + ":" +i + ":" +s;
		} else {
			return 	y + "-" + m + "-" + d;
		}
	},
	getTimeStr: function ()
	{
		var date = new Date();
		var y = date.getFullYear()+""; if(y.length != 4) return false;
		var m = (date.getMonth()+1)+""; if(m.length == 1) m = "0" + m;
		var d = date.getDate()+""; if(d.length == 1) d = "0" + d;
		var h = date.getHours()+""; if(h.length == 1) h = "0" + h;
		var i = date.getMinutes()+""; if(i.length == 1) i = "0" + i;
		var s = date.getSeconds()+""; if(s.length == 1) s = "0" + s;
		return y + "-" + m + "-" + d + " " + h + ":" + i + ":" + s;
	},
	htmlspecialchars: function(str){            
          str = str.replace(/&/g, '&amp;');  
          str = str.replace(/</g, '&lt;');  
          str = str.replace(/>/g, '&gt;');  
          str = str.replace(/"/g, '&quot;');  
          str = str.replace(/'/g, '&#039;');  
          return str;  
	},
	deepCopy: function(obj) {
		if (typeof obj.constructor === 'undefined') return null;
		var newobj = obj.constructor === Array ? [] : {};
		if (typeof obj !== 'object') {
			return obj;
		} else {
			for (var i in obj) {
				if (typeof obj[i] === 'object'){
					if(obj[i] == null) newobj[i] = null;
					else newobj[i] = $G.deepCopy(obj[i]); 
				}else{
					newobj[i] = obj[i];
				}
			}
		}
		return newobj;
	},
	rsa_encrypt: function(str) {
		var rkey;
		var encrypt = new JSEncrypt();

		encrypt.setPublicKey(rsa_pubkey);
		return encrypt.encrypt(str);
	},
	aes_encrypt: function(str, aesKey) {
		try {
			var key = CryptoJS.enc.Utf8.parse(aesKey);
			var encrypt = CryptoJS.AES.encrypt(str, key, {
				 iv: CryptoJS.enc.Utf8.parse(aesKey.substr(0,16)),
				 mode: CryptoJS.mode.CBC,
				 padding: CryptoJS.pad.Pkcs7
			});
			return encrypt.toString();
		} catch (e) {
			return "";
		}
	},
	aes_decrypt: function(str, aesKey) {
		try {
			var key = CryptoJS.enc.Utf8.parse(aesKey);
			var decrypt = CryptoJS.AES.decrypt(str, key, {
				iv: CryptoJS.enc.Utf8.parse(aesKey.substr(0,16)),
				mode: CryptoJS.mode.CBC,
				padding: CryptoJS.pad.Pkcs7
			});
			return decrypt.toString(CryptoJS.enc.Utf8);
		} catch (e) {
			return "";
		}
		
	},
	httpPost: function(URL, PARAMS, target) {
		var temp = document.createElement("form");
		temp.action = URL;
		temp.method = "post";
		temp.target = target;
		temp.style.display = "none";
		if(!PARAMS) PARAMS = {};

		for (var x in PARAMS) {
			var opt = document.createElement("textarea");
			opt.name = x;
			opt.value = PARAMS[x];
			temp.appendChild(opt);
		}

		document.body.appendChild(temp);
		$G.submitForm(temp);
		document.body.removeChild(temp);
		return temp;
	},

	getElementLeft: function(element){
		var actualLeft = element.offsetLeft;
		var current = element.offsetParent;

		while (current !== null){
		  actualLeft += current.offsetLeft;
		  current = current.offsetParent;
		}

		return actualLeft;
	},

	getElementTop: function(element){
		var actualTop = element.offsetTop;
		var current = element.offsetParent;

		while (current !== null){
		  actualTop += current.offsetTop;
		  current = current.offsetParent;
		}

		return actualTop;
	},
	copy: function(s) {
		var textarea = document.createElement('textarea');
		document.body.appendChild(textarea);
		textarea.innerHTML = s;
		textarea.select();
		document.execCommand('copy');
		document.body.removeChild(textarea);
	},
	stopBubbling: function(event) {
		event = event || window.event;
		if (event.stopPropagation) {
			event.stopPropagation();
		} else {
			// IE 及以下版本
			event.cancelBubble = true;
		}
	}
};
